<?php
if(!defined('ADMINPX') || !defined('ADMIN')) {
	exit('Access Denied');
}
$act=$_GET['act'];
$id=$_GET['id'];
$fid=$_GET['fid'];
$flid=$_GET['flid'];
$aa=$_GET['aa'];
if($act=='cjltok'){
	if($_POST[sc] =='1'){
    if(!$_POST[adminpost]){
	     echo"提交出错<br/>";
	  }elseif($db->insert('forum_class',array('id' => 'NULL' ,'fid' => $fid,'px' => $_POST[px],'type' => '1', 'pass' => '','name' => $_POST[name],'value' => $_POST[value],'logo' => ''))){
       echo"创建论坛成功<br/>";
    }else{
		   echo"创建论坛失败<br/>";
    }
	}else if($_POST[sc] =='2'){
          $bzwjc=Bingz_upload('forum/logo/','1','1');
          if($bzwjc[1] == '1'){
             if(!$_POST[adminpost]){
	              echo"提交出错<br/>";
	           }elseif($db->insert('forum_class',array('id' => 'NULL' ,'fid' => $fid,'px' => $_POST[px] ,'name' => $_POST[name],'value' => $_POST[value],'logo' => 'data/forum/logo/'.$bzwjc[2]))){
                echo"创建论坛成功<br/>";
             }else{
		            echo"创建论坛失败<br/>";
             }
    	    }else{
		           echo"修改图片失败<br/>上传附件：".$bzwjc[2]."<br/>";
          } 
  }
  echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum'>";
}else if($act=='cjlt'){
echo <<<end
<div class="admin">创建论坛<br/></div>
end;
echo <<<end
<form method="POST" action="admin.php?action=forum&act=cjltok&fid=$fid" enctype="multipart/form-data" >
图标: 
<INPUT type=radio CHECKED value=1 name="sc">系统默认
<INPUT type=radio value=2 name="sc">上传图标
<input type="file" name="upfile" />
<br/>
排序：<input class="text" type="text" name="px" value="0" size=25/><br/>
名称：<input class="text" type="text" name="name" value="输入名称" size=25/><br/>
简介：<input class="text" type="text" name="value" value="简介" size=25/><br/>
<input type="submit" value="确定创建论坛" name="adminpost" />
</form>
end;
}else if($act=='xgltok'){      
    if(!$_POST[adminpost]){
	       echo"提交出错<br/>";
	  }elseif($db->update('forum_class',array('sz_fbqx' => $_POST[fbqx] ,'type' => $_POST[xs] ,'px' => $_POST[px] ,'sz_ydqx' => $_POST[sz_ydqx] ,'pass' => $_POST[pass] ,'value' => $_POST[value] ,'sz_fl' => $_POST[sz] ,'name' => $_POST[name] )," `id`= '$id'")){
    	 if($_POST[sc] =='1'){
    	    	 		  $row=$db->get_one('forum_class'," `id` ='$id'",'');
                  $ssid=explode("/",$row[logo]);
                  if($ssid[2] == 'sc'){
                  	@unlink (Bingz_upload_images("$row[logo]"));
                    @unlink("$row[logo]");
                  }
    	    	 		  $db->update('forum_class',"`logo`='0' ","  `id`= '$id'");
    	 }else if($_POST[sc] =='2'){
          $bzwjc=Bingz_upload('forum/logo/','1','1');
          if($bzwjc[1] == '1'){
    	    	 		 $row=$db->get_one('forum_class',"  `id` ='$id'",'');
                 if($db->update('forum_class',array('logo' => 'data/forum/logo/'.$bzwjc[2])," `id`= '$id'")){
                    $ssid=explode("/",$row[logo]);
                    if($ssid[2] == 'logo'){
                  	  @unlink (Bingz_upload_images("$row[logo]"));
                      @unlink ("$row[logo]");
                    }
	                  echo"修改图片成功<br/>";
                 }else{
		                echo"修改图片失败<br/>";
                 }
    	    }else{
		                echo"修改图片失败<br/>上传附件：".$bzwjc[2]."<br/>";
          } 
       }	 	
	     echo"修改论坛成功</strong><br/>";
    }else{
		   echo"修改失败<br/>";
    }
    echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&act=xglt&id=$id\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum&act=xglt&id=$id'>";   
}else if($act=='xglt'){
echo <<<end
<div class="admin">论坛管理<br/></div>
<a href="admin.php?action=forum&act=zjtzfl&id=$id&fid=$fid">增加帖子分类</a>
<br/><div class="admin_a">
end;
  $sql=$db->query('forum_tzfl'," `fid` = '$id' ",'');
	while($rowa=mysql_fetch_array($sql)){
    echo "<a href=\"admin.php?action=forum&act=xgtzfl&flid=$rowa[id]&fid=$rowa[fid]&id=$id\">$rowa[name]</a> - ";
		$l_sa++;
	}
$row=$db->get_one('forum_class'," `id` ='$id'",'');
if($row[logo] == '0' ){
	 if($row[tzszj] > 0 ){
	    $logo="images/forum/forum_new.gif";
	 }else{
	    $logo="images/forum/forum.gif";
	 }
}else{
   $logo="$row[logo]";
}
if($row[sz_ydqx]== '1'){ $a="CHECKED "; }elseif($row[sz_ydqx] == '2'){ $aa="CHECKED "; }elseif($row[sz_ydqx] == '3'){ $aaa="CHECKED "; }elseif($row[sz_ydqx] == '4'){ $aaaa="CHECKED "; }
if($row[sz_fl]  == '0'){ $b="CHECKED "; }else{ $bb="CHECKED "; }
if($row[sz_fbqx]== '1'){ $c="CHECKED "; }elseif($row[sz_fbqx] == '2'){ $cc="CHECKED "; }elseif($row[sz_fbqx] == '3'){ $ccc="CHECKED "; }elseif($row[sz_fbqx] == '4'){ $cccc="CHECKED "; }elseif($row[sz_fbqx] == '5'){ $ccccc="CHECKED "; }
if($row[type]   == '1'){ $d="CHECKED "; }else{ $dd="CHECKED "; }
echo <<<end
<form method="POST" action="admin.php?action=forum&act=xgltok&id=$row[id]&fid=$fid" enctype="multipart/form-data" >
</div>
图标: <img src="$logo" /><br/>
<INPUT type=radio CHECKED value=0 name="sc">不修改
<INPUT type=radio value=1 name="sc">系统默认
<INPUT type=radio value=2 name="sc">上传图标
<input type="file" name="upfile" />
<br/>
排序：<input class="text" type="text" name="px" value="$row[px]" size=25/><br/>
名称：<input class="text" type="text" name="name" value="$row[name]" size=25/><br/>
简介：<input class="text" type="text" name="value" value="$row[value]" size=25/><br/>
浏览权限: 
<INPUT type=radio $a value=1 name="sz_ydqx">不限
<INPUT type=radio $aa value=2 name="sz_ydqx">登陆
<br/>
发表权限: 
<INPUT type=radio $c value=1 name="fbqx">不限
<INPUT type=radio $cc value=2 name="fbqx">版主
<INPUT type=radio $ccc value=3 name="fbqx">管理员
<INPUT type=radio $cccc value=4 name="fbqx">系统员
<INPUT type=radio $ccccc value=5 name="fbqx">禁止
<br/>
帖子分类: 
<INPUT type=radio $b value=0 name="sz">关闭
<INPUT type=radio $bb value=1 name="sz">开启
<br/>
显示设置: 
<INPUT type=radio $d value=1 name="xs">显示
<INPUT type=radio $dd value=2 name="xs">隐藏
<br/>
<input class="submit" type="submit" value="编辑" name="adminpost" />
</form><br/>
<a href="admin.php?action=forum&act=scltts&id=$row[id]">删除论坛</a><br/>
end;
}else if($act=='zjtzflok'){
    	    if(!$_POST[adminpost]){
	           echo"提交出错<br/>";
	        }elseif($db->insert('forum_tzfl',array('id' => 'NULL','fid' => $id,'px' => $_POST[px],'foid' => 0,'name' => $_POST[name]))){
	           echo"增加帖子分类成功<br/>";
          }else{
		         echo"增加帖子分类失败<br/>";
          }
         echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&act=xglt&id=$id\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum&act=xglt&id=$id'>";
}else if($act=='xgtzflok'){
    	    if(!$_POST[adminpost]){
	           echo"提交出错<br/>";
	        }elseif($db->update('forum_tzfl',array('px' => $_POST[px] ,'name' => $_POST[name]),"`id`= '$flid'")){
	           echo"修改帖子分类成功<br/>";
          }else{
		         echo"修改分类失败<br/>";
          }
         echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&act=xglt&id=$id\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum&act=xglt&id=$id'>";
}else if($act=='sctzfl'){
  $db->delete('forum_tzfl',"  `id` = '$flid'");
	echo "删除成功<br/>";
  echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&act=xglt&id=$id\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum&act=xglt&id=$id'>";
}else if($act=='xgtzfl'){
$row=$db->get_one('forum_tzfl'," `id` ='$flid'",'');
echo <<<end
<div class="admin">修改帖子分类<br/></div>
<form method="POST" action="admin.php?action=forum&act=xgtzflok&id=$id&flid=$flid" enctype="multipart/form-data" >
排序<input type="text" name="px" value="$row[px]" size=25/><br/>
名称<input type="text" name="name" value="$row[name]" size=25/><br/>
<input type="submit" value="确定修改" name="b1" />
</form>
<a href="admin.php?action=forum&act=sctzfl&flid=$row[id]&id=$row[fid]">删除帖子分类</a><br/>
end;
}else if($act=='zjtzfl'){
echo <<<end
<div class="admin">增加帖子分类<br/></div>
<form method="POST" action="admin.php?action=forum&act=zjtzflok&id=$id" enctype="multipart/form-data" >
排序<input type="text" name="px" value="0" size=25/><br/>
名称<input type="text" name="name" value="教程" size=25/><br/>
<input type="submit" value="确定增加" name="adminpost" />
</form>
end;
}else if($act=='zjflok'){
    	    if(!$_POST[adminpost]){
	           echo"提交出错<br/>";
	        }elseif($db->insert('forum_class_fl',array('id' => 'NULL','px' => $_POST[px],'type' => 1,'name' => $_POST[name],'logo' => $_POST[logo]))){
	           echo"增加分类成功<br/>";
          }else{
		         echo"增加分类失败<br/>";
          }
          echo "正在自动返回.......<br/><a href=\"admin.php?action=forum\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum'>";
}else if($act=='scltts'){
	 echo"注意：删除论坛后直接删除论坛下属帖子！<br/>";
   echo "<a href=\"admin.php?action=forum&act=sclt&id=$id\">确定删除</a><br/>";
}else if($act=='sclt'){
	$sqla=$db->query('forum'," `cid` ='$id' ORDER BY `id` ","");
	while($rowa=mysql_fetch_array($sqla)){

	$sql=$db->query('forum_data'," `fid` ='$row[id]'ORDER BY `id` ","");
	while($row=mysql_fetch_array($sql)){
       @unlink (Bingz_upload_images('data/forum/'.$row[url].''));
       @unlink ("data/forum/".$row[url]."");
   	   $db->delete('forum_data'," `id` = '$row[id]'");
		   $db->delete('forum_data_user'," `fid` = '$row[id]'");
  }
		     $db->delete('forum_hui'," `fid` = '$rowa[id]'");
         $db->delete('forum'," `id` = '$rowa[id]'");
  }
	$db->delete('forum_class'," `id` = '$id'");
	echo "删除成功<br/>";
  echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum'>";
}else if($act=='scflts'){
	 echo"注意：删除分类后直接删除分类下属论坛及帖子！<br/>";
   echo "<a href=\"admin.php?action=forum&act=scfl&id=$id\">确定删除</a><br/>";
}else if($act=='scfl'){
	$sql=$db->query('forum_class'," `fid` ='$id' ORDER BY `id` ","");
	while($row=mysql_fetch_array($sql)){
	     $sqla=$db->query('forum'," `cid` ='$row[id]' ORDER BY `id` ","");
	     while($rowa=mysql_fetch_array($sqla)){
	$sql=$db->query('forum_data'," `fid` ='$row[id]'ORDER BY `id` ","");
	while($row=mysql_fetch_array($sql)){
       @unlink (Bingz_upload_images('data/forum/'.$row[url].''));
       @unlink ("data/forum/".$row[url]."");
   	   $db->delete('forum_data'," `id` = '$row[id]'");
		   $db->delete('forum_data_user'," `fid` = '$row[id]'");
  }
		     $db->delete('forum_hui'," `fid` = '$rowa[id]'");
         $db->delete('forum'," `id` = '$rowa[id]'");
       }
		   $db->delete('forum_class'," `id` = '$row[id]'");
  }
	$db->delete('forum_class_fl'," `id` = '$id'");
	echo "删除成功<br/>";
  echo "正在自动返回.......<br/><a href=\"admin.php?action=forum&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum'>";
}else if($act=='xgflok'){
    	    if(!$_POST[adminpost]){
	           echo"提交出错<br/>";
	        }elseif($db->update('forum_class_fl',array('logo' => $_POST[logo] ,'px' => $_POST[px] ,'type' => $_POST[lx] ,'name' => $_POST[name])," `id`= '$id'")){
	           echo"修改分类成功<br/>";
          }else{
		         echo"修改分类失败<br/>";
          }
       echo "正在自动返回.......<br/><a href=\"admin.php?action=forum\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=admin.php?action=forum'>";
}else if($act=='zjfl'){
echo <<<end
<div class="admin">增加论坛分类<br/></div>
<form method="POST" action="admin.php?action=forum&act=zjflok" enctype="multipart/form-data" >
排序<input type="text" name="px" value="1" size=25/><br/>
名称<input type="text" name="name" value="会员交流" size=25/><br/>
图标<input type="text" name="logo" value="images/forum/forum_logo.jpg" size=25/><br/>
<input type="submit" value="确定增加" name="adminpost" />
</form>
end;
}else{
echo"<a href=\"admin.php?action=forum&act=zjfl\">添加论坛分类</a><br/>";
echo <<<end
<div class="admin">论坛管理<br/></div>
end;
   $sql_fi=$db->query('forum_class_fl',"1 ORDER BY `px`",'');
   $l_s='1';
   while($row=mysql_fetch_array($sql_fi)){
   	$c='';
   	$cc='';
if($row[type] == '1'){ $c="CHECKED "; }else{ $cc="CHECKED "; }
echo <<<end
<div class="admin_b">
<form method="POST" action="admin.php?action=forum&act=xgflok&id=$row[id]" >
$l_s 、<input type="text" name="px" value="$row[px]" size=1/>
<input type="radio" name="lx" value="1"  $c />显
<input type="radio" name="lx" value="0"  $cc />隐
<input type="text" name="name" value="$row[name]" size=5/>
<input type="text" name="logo" value="$row[logo]" size=5/>
<input type="submit" value="编辑" name="adminpost" />
<a href="admin.php?action=forum&act=cjlt&fid=$row[id]">创建论坛</a>
<a href="admin.php?action=forum&act=scflts&id=$row[id]">删除</a>
</form>
</div>
end;
      $sql_li=$db->query('forum_class'," `fid` ='$row[id]' ORDER BY `px`",'');
	    while($rowa=mysql_fetch_array($sql_li)){
      $num_count=$db->num_rows('forum'," `cid` ='$rowa[id]' ",'id');
echo <<<end
<div class="admin_a">&nbsp;&nbsp;&nbsp;
$rowa[name](id:<font color='#FF0000'>$rowa[id]</font>/帖:<font color='#FF0000'>$num_count</font>)
[<a href="admin.php?action=forum&act=xglt&id=$rowa[id]&fid=$row[id]">管理板块</a>]
</div>
end;
      }
   $l_s++;
   }
}
echo "<br/><a href=\"admin.php?action=forum&\">返回论坛管理</a><br/>";
?>